/* File: ImageExtractor.java
 * $Author: junu.pv $
 * $LastChangedDate: 2010-05-02 17:50:49 +0000 (Sun, 02 May 2010) $
 * $Rev: 21 $
 * Licensed under GPL v3
 */
/*
 * OptionsDialog.java
 *
 * Created on 30-Apr-2010, 09:06:01
 */

package wiki2local;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.EnumMap;

/**
 * Dialog helps user to set diffrent options.
 * @author Junaid
 * @version 0.6
 * @since 0.5
 */
public class OptionsDialog extends javax.swing.JDialog {
    public enum Options {
        LANGUAGE,
        PROJECT,
        MENU_ID,
        MENU_CLASS,
        TOPIC_NODE_CLASS,
        TOPIC_ITEM_CLASS,
        PAGE_ITEM_CLASS
    }
    private EnumMap<Options, String> options;

    /** Creates new form OptionsDialog */
    public OptionsDialog(java.awt.Frame parent, boolean modal, EnumMap<Options, String> options) {
        super(parent, modal);
        initComponents();
        this.options = options;
        setDefaults();
        this.addWindowListener(new WindowAdapter(){
            @Override
            public void windowClosing(WindowEvent event) {
                closeWindow();
            }
        });
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        languageTextField = new javax.swing.JTextField();
        projectCombo = new javax.swing.JComboBox();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        menuIdTextField = new javax.swing.JTextField();
        menuClassTextField = new javax.swing.JTextField();
        topicNodeClass = new javax.swing.JTextField();
        topicItemClass = new javax.swing.JTextField();
        pageItemClass = new javax.swing.JTextField();
        okButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        resetButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Options");
        setResizable(false);

        jLabel1.setText("Wiki Language:");

        jLabel2.setText("Wiki Project:");

        languageTextField.setText("ml");

        projectCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "wikipedia", "wikibooks", "wikisource", "wiktionary", "wikiversity" }));

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel3.setText("Menu ID (topmost UL tag id):");

        jLabel4.setText("Menu Class (topmost UL tag css class):");

        jLabel5.setText("Topic Node Class (topic node LI tag css class):");

        jLabel6.setText("Topic Node Item Class (topic node SPAN css clss):");

        jLabel7.setText("Page Node Item Class (page node SPAN css class):");

        jLabel8.setText("<html>These are HTML tag properties of that form TOC tree. Most of the time there will be no need to change these items.</html>");

        menuIdTextField.setText("jTextField1");
        menuIdTextField.setMinimumSize(new java.awt.Dimension(50, 20));

        menuClassTextField.setText("jTextField2");
        menuClassTextField.setMinimumSize(new java.awt.Dimension(50, 20));

        topicNodeClass.setText("jTextField3");
        topicNodeClass.setMinimumSize(new java.awt.Dimension(50, 20));

        topicItemClass.setText("jTextField4");
        topicItemClass.setMinimumSize(new java.awt.Dimension(50, 20));

        pageItemClass.setText("jTextField5");
        pageItemClass.setMinimumSize(new java.awt.Dimension(50, 20));

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel8, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 310, Short.MAX_VALUE)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel7)
                            .add(jLabel6)
                            .add(jLabel5)
                            .add(jLabel4)
                            .add(jLabel3))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(menuIdTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE)
                            .add(menuClassTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE)
                            .add(topicNodeClass, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE)
                            .add(topicItemClass, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE)
                            .add(pageItemClass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 56, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel8, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(menuIdTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(menuClassTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(topicNodeClass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel6)
                    .add(topicItemClass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel7)
                    .add(pageItemClass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        okButton.setText("OK");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        resetButton.setText("Reset");
        resetButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resetButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(10, 10, 10)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jLabel1)
                        .add(18, 18, 18)
                        .add(languageTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 34, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(layout.createSequentialGroup()
                        .add(jLabel2)
                        .add(31, 31, 31)
                        .add(projectCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(layout.createSequentialGroup()
                        .add(resetButton)
                        .add(81, 81, 81)
                        .add(okButton)
                        .add(80, 80, 80)
                        .add(cancelButton)))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(11, 11, 11)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(3, 3, 3)
                        .add(jLabel1))
                    .add(languageTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(3, 3, 3)
                        .add(jLabel2))
                    .add(projectCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(6, 6, 6)
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(11, 11, 11)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(resetButton)
                    .add(okButton)
                    .add(cancelButton))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void closeWindow() {
        this.setDefaults();
        this.setVisible(false);
        this.dispose();
    }
    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_okButtonActionPerformed

    private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetButtonActionPerformed
        this.setDefaults();
    }//GEN-LAST:event_resetButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        this.setDefaults();
        this.setVisible(false);
    }//GEN-LAST:event_cancelButtonActionPerformed

    public void setDefaults() {
        this.languageTextField.setText(this.options.get(Options.LANGUAGE));
        this.projectCombo.setSelectedItem(this.options.get(Options.PROJECT));
        this.menuIdTextField.setText(this.options.get(Options.MENU_ID));
        this.menuClassTextField.setText(this.options.get(Options.MENU_CLASS));
        this.topicNodeClass.setText(this.options.get(Options.TOPIC_NODE_CLASS));
        this.topicItemClass.setText(this.options.get(Options.TOPIC_ITEM_CLASS));
        this.pageItemClass.setText(this.options.get(Options.PAGE_ITEM_CLASS));
    }
    public String getLanguage() {
        return this.languageTextField.getText();
    }
    public String getProject() {
        return this.projectCombo.getSelectedItem().toString();
    }
    public String getMenuId() {
        return this.menuIdTextField.getText();
    }
    public String getMenuClass() {
        return this.menuClassTextField.getText();
    }
    public String getTopicNodeClass() {
        return this.topicNodeClass.getText();
    }
    public String getTopicItemClass() {
        return this.topicItemClass.getText();
    }
    public String getPageItemClass() {
        return this.pageItemClass.getText();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField languageTextField;
    private javax.swing.JTextField menuClassTextField;
    private javax.swing.JTextField menuIdTextField;
    private javax.swing.JButton okButton;
    private javax.swing.JTextField pageItemClass;
    private javax.swing.JComboBox projectCombo;
    private javax.swing.JButton resetButton;
    private javax.swing.JTextField topicItemClass;
    private javax.swing.JTextField topicNodeClass;
    // End of variables declaration//GEN-END:variables

}
